﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Nature
{
    public partial class IdealGasMixture
    {
        void __calc_visck(double[] vk)
        {
            Model.IdealGasSpeciesMolecularTransportProperties
                .CalcSpeciesIdealGasViscosities(
                m_temperature.Value,
                vk);
        }

        void __calc_lambk(double[] lk)
        {
            Model.IdealGasSpeciesMolecularTransportProperties
                .CalcSpeciesIdealGasThermalConductivities(
                m_temperature.Value,
                lk);
        }

        void __calc_difkkp0(double[] dkk)
        {
            Model.IdealGasSpeciesMolecularTransportProperties
                .CalcSpeciesIdealGasSelfDiffusivities(
                m_temperature.Value, 
                Constants.Rgas,
                dkk);
        }

        void __calc_difkk(double[] dkk)
        {
            Model.IdealGasSpeciesMolecularTransportProperties
                .CalcSpeciesIdealGasSelfDiffusivities(
                m_temperature.Value,
                m_pressure.Value,
                dkk);
        }

        void __calc_wilke(double[][] wilke)
        {
            var x = m_speciesMoleFractions.Array;
            var v = m_speciesViscosities.Array;
            var matrixG1 = Model.WilkeGroup1.Data;
            var matrixG2 = Model.WilkeGroup2.Data;

            for (int isp = 0; isp < Nsp; ++isp)
            {
                double[] r = wilke[isp];
                var g1 = matrixG1[isp];
                var g2 = matrixG2[isp];
                for (int jsp = 0; jsp < Nsp; ++jsp)
                {
                    if (isp == jsp) { r[jsp] = 1.0; continue; }
                    double u = 1.0 + Math.Sqrt(v[isp] / v[jsp]) * g1[jsp];
                    r[jsp] = u * u / g2[jsp];
                }
            }
        }

        void __calc_bindiff(double[][] djk)
        {
            Model.IdealGasSpeciesMolecularTransportProperties
                .CalcSpeciesIdealGasDiffusivities(
                    m_temperature.Value,
                    m_pressure.Value,
                    djk);
        }

        void __calc_bindiffp0(double[][] djk)
        {
            Model.IdealGasSpeciesMolecularTransportProperties
                .CalcSpeciesIdealGasDiffusivities(
                    m_temperature.Value,
                    Constants.Atmosphere,
                    djk);
        }

        void __calc_bintau(double[][] taujk)
        {
            Model.IdealGasSpeciesMolecularTransportProperties
                .CalcSpeciesIdealGasThermoDiffusivities(
                    m_temperature.Value,
                    taujk);
        }

        double __calc_visc()
        {
            return Model.IdealGasMixtureMolecularTransportProperties.CalcMixtureIdealGasViscosity(this);
        }

        double __calc_cond()
        {
            return Model.IdealGasMixtureMolecularTransportProperties.CalcMixtureIdealGasThermalConductivity(this);
        }

        double __calc_diff()
        {
            return Model.IdealGasMixtureMolecularTransportProperties.CalcMixtureIdealGasDiffusivity(this);
        }
    }
}
